/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package map;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author sfsuarez
 */
public class absconect {
    Statement sentencia = null;
    Connection con = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    
     
     
     public boolean conectar ( String user, String pswd, String host, String port ){
         
         
            String cadena_conex = "jdbc:oracle:thin:@"+host+":"+port +"/qabd";

            String usuario = user;
            String clave = pswd;
                 boolean conectado=false;
                try {


                        DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
                        con = DriverManager.getConnection(cadena_conex, usuario, clave);
                        sentencia = con.createStatement();
                        conectado = true;
                } catch (SQLException ex) {
                    Logger.getLogger(absconect.class.getName()).log(Level.SEVERE, null, ex);
                    // conectado = "Error: [" +ex.getMessage()+"]";
                      conectado = false;
                }
                return conectado;
	     
     
     }//end conectar
     
     
     
      public ResultSet consulta ( String sql ){
          
                   try {


                        rs = sentencia.executeQuery( sql );

                    }catch (SQLException ex) {
                        Logger.getLogger(absconect.class.getName()).log(Level.SEVERE, null, ex);
                        System.out.println(ex.toString());

                        rs = null;
                    }

                    return rs;
     }//end consulta
      
      
      public int borrar_registro ( String sql ){
          int delete =0;
                   try {



                        rs = sentencia.executeQuery( sql );
                        
                        delete = sentencia.getUpdateCount();

                    }catch (SQLException ex) {
                        Logger.getLogger(absconect.class.getName()).log(Level.SEVERE, null, ex);
                        System.out.println(ex.toString());

                        rs = null;
                    }

                    return delete;
     }//end consulta
      
    
    public int update (String sql){
        int rows =0;
        
        try {
            rows = sentencia.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(absconect.class.getName()).log(Level.SEVERE, null, ex);
        }
        return rows;
    }//end update
    
    
    
     public void Cerrarconex(){
            try {
                if (rs!=null) rs.close();
                if (stmt!=null) stmt.close();   
                if (con!=null) con.close();
            } //end Cerrarconex
            catch (SQLException ex) {
                Logger.getLogger(absconect.class.getName()).log(Level.SEVERE, null, ex);
            }
    }//end Cerrarconex
}
